import { CopyInfoPanelBase } from "../copy/CopyInfoPanelBase";
import { Language } from "../../../../extend/language/Language";
import { Cache } from "../../cache/Cache";
import { SRaceReachPoint } from "../../../../Message/Public/SRaceReachPoint";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { SRaceRoomInfo } from "../../../../Message/Public/SRaceRoomInfo";
import { ClockManager } from "../../manager/ClockManager";
import { SRaceRoomPlayerNum } from "../../../../Message/Public/SRaceRoomPlayerNum";
import { SecTimerView } from "../common/SecTimerView";
import { ObjCreate } from "../common/ObjCreate";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { Lv70DramaItem } from "../lv70fb/data/Lv70DramaItem";
import { ConstConfig } from "../../resource/ConstConfig";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
type int = number;
//class RaceCopyInfoPanel
    
    export  class RaceCopyInfoPanel extends CopyInfoPanelBase
    {
        constructor()
        {
            super();
            this.initView();
            updatePosition();
            return;
        }

        public updateTodayTimes(): void
        {
            this._txtTodayTimes.htmlText = Language.getStringByParam(80167, Cache.instance.copy.getCopyNumInfoByCode(152).todayEnterNum.toString());
            return;
        }

        public updateFininshProgress(arg1: SRaceReachPoint): void
        {
            this._txtFinish.htmlText = Language.getStringByParam(80153, arg1.index.toString() + "/" + arg1.maxIndex.toString());
            return;
        }

        /* internal  */getColorByPlayerNum(arg1: int): string
        {
            if (this._roomInfo == null) 
            {
                return GlobalStyle.color7;
            }
            if (arg1 >= this._roomInfo.startMinPlayerNum) 
            {
                return GlobalStyle.color6;
            }
            if (!(this._roomInfo.startMinPlayerNum == this._roomInfo.maxPlayerNum) && arg1 < this._roomInfo.startMinPlayerNum) 
            {
                return GlobalStyle.color7;
            }
            return GlobalStyle.color5;
        }

        public updateRoomInfo(arg1: SRaceRoomInfo): void
        {
            if (arg1 == null) 
            {
                return;
            }
            this._roomInfo = arg1;
            var loc1=ClockManager.instance.nowDate.time - arg1.predictDt.time;
            var loc2=this.getColorByPlayerNum(arg1.playerNum);
            var loc3="<font color=\'" + loc2.toString() + "\'>" + Language.getStringByParam(80159, arg1.playerNum.toString(), arg1.maxPlayerNum.toString()) + "</font>";
            if (arg1.isStart) 
            {
                this._leftTimer.visible = false;
                this._txtStart.htmlText = Language.getString(80163) + loc3;
                this._txtStart.x = this._leftTimer.x;
                return;
            }
            if (loc1 < 0) 
            {
                if (arg1.playerNum >= arg1.maxPlayerNum) 
                {
                    this._leftTimer.visible = false;
                    this._txtStart.htmlText = Language.getString(80162) + loc3;
                    this._txtStart.x = this._leftTimer.x;
                }
                else 
                {
                    this._leftTimer.visible = true;
                    this._leftTimer.setParse(Language.getString(80160));
                    this._leftTimer.setLeftTime(Math.ceil((-loc1) / 1000));
                    this._leftTimer.timeOutHandler = this.leftTimeEndHandler;
                    this._txtStart.htmlText = loc3;
                    this._txtStart.x = this._leftTimer.x + 148;
                }
            }
            else 
            {
                this._leftTimer.visible = false;
                this._txtStart.htmlText = Language.getString(80161) + loc3;
                this._txtStart.x = this._leftTimer.x;
            }
            return;
        }

        /* internal  */leftTimeEndHandler(): void
        {
            this._leftTimer.stop();
            if (this._roomInfo.isStart) 
            {
                return;
            }
            this.updateRoomInfo(this._roomInfo);
            return;
        }

        public updateRoomPlayerNum(arg1: SRaceRoomPlayerNum): void
        {
            this._roomInfo.playerNum = arg1.playerNum;
            this.updateRoomInfo(this._roomInfo);
            return;
        }

        /* internal  */initView(): void
        {
            var loc2=null;
            var loc4=null;
            _bg.bitmapData = new Object /* flash.display.BitmapData */(260, 256, false, 0);
            _bg.y = 22;
            _bg.alpha = 0.45;
            this._leftTimer = new SecTimerView();
            ObjCreate.setObjAttri(this._leftTimer, 10, 57, 300, 30, _bodySp);
            var loc1=new GTextFormat(FontUtil.songtiName, 14, 16580352);
            loc1.bold = true;
            this._leftTimer.textColor = 16776960;
            this._leftTimer.defaultTextFormat = loc1;
            this._leftTimer.filters = [FilterConst.glowFilter];
            this._leftTimer.setParse(Language.getString(80160));
            this._leftTimer.mouseEnabled = false;
            this._leftTimer.mouseWheelEnabled = false;
            this._txtStart = ObjCreate.createGTextField("", 10, 57, 300, 20, _bodySp);
            loc1 = this._txtStart.defaultTextFormat;
            loc1.size = 14;
            loc1.bold = true;
            this._txtStart.defaultTextFormat = loc1;
            this._txtStart.mouseEnabled = false;
            loc2 = ObjCreate.createGTextField("", 8, 4, 250, 70, _bodySp);
            loc2.textColor = GlobalStyle.color1Uint;
            loc1 = loc2.defaultTextFormat;
            loc1.leading = 5;
            loc2.multiline = true;
            loc2.wordWrap = true;
            loc2.mouseEnabled = false;
            loc2.defaultTextFormat = loc1;
            loc2.htmlText = Language.getString(80156);
            this._txtFinish = ObjCreate.createGTextField("", 12, 73, 200, 50, _bodySp);
            loc1.size = 30;
            loc1.font = FontUtil.stXingkaiName;
            this._txtFinish.defaultTextFormat = loc1;
            this._txtFinish.mouseEnabled = false;
            loc2 = ObjCreate.createGTextField("", 8, 108, 250, 80, _bodySp);
            loc2.textColor = GlobalStyle.color1Uint;
            loc2.multiline = true;
            loc2.wordWrap = true;
            loc2.mouseEnabled = false;
            loc1 = loc2.defaultTextFormat;
            loc1.leading = 4;
            loc2.defaultTextFormat = loc1;
            loc2.htmlText = Language.getString(80157);
            ObjCreate.createBg(4, 175, 240, 2, _bodySp, ImagesConst.SplitLine);
            loc2 = ObjCreate.createGTextField("", 8, 178, 215, 20, _bodySp);
            loc2.htmlText = Language.getString(80158);
            var loc3=0;
            while (loc3 < 5) 
            {
                (loc4 = new Lv70DramaItem()).itemCode = int(ConstConfig.instance.getValueByName(this.BonusNames[loc3] as string));
                loc4.amount = 1;
                loc4.x = 14 + 46 * loc3;
                loc4.y = 199;
                _bodySp.addChild(loc4);
                ++loc3;
            }
            this._txtTodayTimes = ObjCreate.createGTextField("", loc2.x, loc2.y + 46 + 12, 215, 20, _bodySp);
            this._txtTodayTimes.textColor = 65280;
            this.updateTodayTimes();
            return;
        }

        /* internal */ /* const */BonusNames: Array<any>=["RaceCopyRankIn1", "RaceCopyRankIn3", "RaceCopyRankIn10", "RaceCopyPerfectNum5", "RaceCopyPerfectNum4", "RaceCopyPerfectNum3", "RaceCopyPerfectNum2", "RaceCopyPerfectNum1"];

        /* internal */ /* var */_leftTimer: SecTimerView;

        /* internal */ /* var */_txtStart: GTextFiled;

        /* internal */ /* var */_txtFinish: GTextFiled;

        /* internal */ /* var */_txtTodayTimes: GTextFiled;

        /* internal */ /* var */_roomInfo: SRaceRoomInfo;
    }
